package com.qidian.mes.qc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.pojo.Iqc;
import com.qidian.mes.qc.mapper.IqcMapper;
import com.qidian.mes.qc.service.IqcService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class IqcServiceImpl implements IqcService {
    @Autowired
    private IqcMapper iqcMapper;

    @Override
    public MESResult queryById(Long iqcId) {
        Iqc iqc = null;
        if ((iqc = iqcMapper.selectById(iqcId)) != null) {
            return MESResult.ok(iqc);
        }
        return MESResult.empty();
    }

    @Override
    public MESResult list(int page, int limit, Iqc iqc) {
        // 开启分页 在当前线程中执行下一条SQL的时候就会进行分页。
        PageHelper.startPage(page, limit);
        List<Iqc> list = iqcMapper.list(iqc);
        // 组织一个分页对象。（页码，每页大小，最大页码，数据，总条数）
        PageInfo<Iqc> pageInfo = new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }

    @Override
    public MESResult save(Iqc iqc) {
        iqcMapper.save(iqc);
        return MESResult.ok();
    }

    @Override
    public MESResult update(Iqc iqc) {
        iqcMapper.update(iqc);
        return MESResult.ok();
    }

    @Override
    public MESResult deleteByIqcId(Long iqcId) {
        iqcMapper.deleteByIqcId(iqcId);
        return MESResult.ok();
    }

    @Override
    public MESResult deletesByIqcId(Long[] iqcId) {
        int  count = iqcMapper.deletesByIqcId(iqcId);
        return  MESResult.ok(count+"");
    }
}
